package com.kaifamiao.www.demo.do0809;

//import com.kaifamiao.www.Do29.pm.Person;

import java.util.Arrays;

public class Demo {
    public static void main(String[] args) {
        //自动装箱
        Integer num = Integer.valueOf(1);
        Integer num1 = 2;

        //比较值是否相等
        //比较大小，compare/compareTo  0  > 0    <0
        Integer[] nums = {6,4,9,5,3,7};
        //排序
        Arrays.sort(nums);

        System.out.println(Arrays.toString(nums));


        /**
         * 自然顺序，实现java.lang,Comparable接口compareTo 自然比较方法
         */
        Person p = new Person();
        p.setName("张三");
        p.setAge(10);

        Person p1 = new Person();
        p1.setName("李四");
        p1.setAge(8);

        Person p2 = new Person();
        p2.setName("王五");
        p2.setAge(11);

        Person p3 = new Person();
        p3.setName("赵六");
        p3.setAge(5);

        Person[] persons = new Person[]{p,p1,p2,p3};
//        Arrays.sort(persons);
        sort(persons);
        System.out.println(Arrays.toString(persons));

    }
    public static void sort(Person[] persons){
        for(int i = 0;i <persons.length-1;i++){
            for (int j = 0;j < persons.length-1-i;j++){
                if(persons[j].compareTo(persons[j+1])>0){
                    Person p = persons[j];
                    persons[j] = persons[j+1];
                    persons[j+1] = p;
                }
            }
        }
    }
}
